package com.yoyo.itravel.dao;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.Date;
import java.util.Map;

/**
 * @Description 用户表-景点表中间表：用户收藏景点持久层接口
 * @Author HZX
 * @Version 1.0
 * @Date 2020/6/26 11:29
 */
@Repository
public interface ISightCollectDao {

    /**
     * @Description 插入收藏数据
     * @Param userId
     * @Param sightId
     * @Param collectTime
     * @Return int
     */
    @Insert("insert into middle_tb_sight_collect(userId,sightId,collectTime) values(#{userId},#{sightId},#{collectTime})")
    int insert(@Param("userId") String userId, @Param("sightId") String sightId, @Param("collectTime") Date collectTime) throws SQLException;

    /**
     * @Description 通过用户id和景点id删除景点收藏数据
     * @Param userId
     * @Param sightId
     * @Return int
     */
    @Delete("delete from middle_tb_sight_collect where userId=#{userId} and sightId=#{sightId}")
    int deleteByUserIdAndSightId(@Param("userId") String userId, @Param("sightId") String sightId) throws SQLException;

    /**
     * @Description 通过用户id和景点id查询景点收藏时间
     * @Param userId
     * @Param sightId
     * @Return java.lang.String
     */
    @Select("select collectTime from middle_tb_sight_collect where userId=#{userId} and sightId=#{sightId}")
    Date selectCollectTimeByUserIdAndSightId(@Param("userId") String userId, @Param("sightId") String sightId) throws SQLException;

    /**
     * @Description 通过用户id查找该用户的所有景点收藏数据
     *
     * @Param userId
     * @Return java.util.Map<java.lang.String , java.util.Date>
     */
    @Select("select sightId, collectTime from middle_tb_sight_collect where userId=#{userId}")
    @Results(value = {
            @Result(id = true, property = "sightId", column = "sightId"),
            @Result(property = "collectTime", column = "collectTime", javaType = Date.class)
    })
    Map<String, Object> selectSightIdAndCollectTimeByUserId(String userId) throws SQLException;

    /**
     * @Description 通过景点id查找该景点的所有用户收藏数据
     *
     * @Param sightId
     * @Return java.util.Map<java.lang.String , java.util.Date>
     */
    @Select("select userId, collectTime from middle_tb_sight_collect where sightId=#{sightId}")
    @Results(value = {
            @Result(id = true, property = "userId", column = "userId"),
            @Result(property = "collectTime", column = "collectTime", javaType = Date.class)
    })
    Map<String, Object> selectUserIdAndCollectTimeBySightId(String sightId) throws SQLException;

}